<script setup>
import {InfoCircleOutlined} from "@ant-design/icons-vue";
import {message} from 'ant-design-vue'
import {getCurrentInstance} from "vue";
import CommentAnalysis from "~/contentScripts/views/tao/detail/components/analysis/components/commentAnalysis.vue";
import Notice from "~/contentScripts/views/tao/detail/components/notice.vue";
import {isLogin} from '~/logic'
import {TRequest} from "~/utils/ali/PCRequest";

const emit = defineEmits(['login'])
const instance = getCurrentInstance()
/**
 * @type ItemInterface
 */
const item = getCurrentInstance().proxy.$item
const commentOrder = ref('1')
const hasContent = ref(false)
const commentNumber = ref(undefined)
const customNumber = ref(undefined)
const commentFilter = ref('全部')
const visible = ref(false)
const spinning = ref(false)
const attributes = ref([]);
const current = ref('')
const __option = getCurrentInstance()?.appContext.provides.option;
const handle = () => {
  if (isLogin({emit}, __option)) {
    current.value = '';
    attributes.value = []
    TRequest.rateLists(item.itemId(), 1).then(res => {
      visible.value = true
      attributes.value = [{
        attributeId: '',
        count: res.total,
        fuzzyCount: res.total,
        title: '全部',
      }, ...res.imprItemVOS];
    });
  }
}
const visibleModal = ref(false);
const handle2 = () => {
  visibleModal.value = true;
}
</script>

<template>
  <div class="bold inner-box btn bold" @click="handle">
    评论分析
  </div>
  <comment-analysis :item="item" :_attribute-id="current" :_comment-filter="commentFilter"
                    :comment-number="commentNumber" :_has-content="hasContent" v-model:visible="visibleModal"
  />
  <a-modal v-model:visible="visible" :width="540" title="评论搜索" :footer="false">
    <a-spin v-model:spinning="spinning">
      <div style="margin-bottom: 5px;">
        <notice />
      </div>
      <a-form
          :label-col="{ span: 4 }"
          :wrapper-col="{ span: 20 }"
      >
        <a-form-item label="评论内容">
          <a-radio-group v-model:value="hasContent">
            <a-radio :value="false">
              全部
            </a-radio>
            <a-radio :value="true">
              有内容
            </a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="评论数量">
          <a-radio-group v-model:value="customNumber">
            <a-radio :value="undefined">
              不限制
            </a-radio>
            <a-radio :value="1">
              自定义
            </a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="评论条数">
          <a-input-number placeholder="评论条数" v-model:value="commentNumber"
                          :disabled="typeof customNumber==='undefined'" min="1" max="100"
          />
        </a-form-item>
        <a-form-item label="评论规则">
          <a-radio-group v-model:value="commentFilter">
            <a-radio value="全部">
              全部
            </a-radio>
            <a-radio value="图片">
              图片
            </a-radio>
            <a-radio value="追评">
              追评
            </a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="大家印象" v-if="attributes.length>0">
          <a-radio-group v-model:value="current">
            <a-radio v-for="item in attributes" :key="item.attributeId" :value="item.attributeId">
              {{ item.title }}({{ item.count }})
            </a-radio>
          </a-radio-group>
        </a-form-item>
      </a-form>
      <a-divider/>
      <a-row type="flex">
        <a-col flex="1">
          <a-button type="primary" size="large" shape="round" block @click="handle2">
            开始分析
          </a-button>
        </a-col>
        <a-col style="width: 50px"/>
        <a-col flex="1">
          <a-button size="large" block shape="round" @click="visible = false">
            取消
          </a-button>
        </a-col>
      </a-row>
    </a-spin>
  </a-modal>
</template>

<style scoped>

</style>
